<template>
	<view class="main">
		<zmm-watermark :watermark="watermark"></zmm-watermark>
		<view class="header">
			<view class="msg" v-if="type == 1">今日盈利（元）</view>
			<view class="msg" v-else>今日亏损（元）</view>
			<view class="num">{{total}}</view>
			<view class="sele" v-if="userInfo.is_leader == 1 || userInfo.is_manager == 1">
				<view class="in">
					<view v-if="userInfo.is_leader == 1"class="left" @tap="routerTo(`/pages/pageB/data/fiter?type=${type}`)">
						<image class="icon1" src="@/static/img/icon1.png" mode="aspectFit"></image>
						<view class="txt">
							员工筛选
						</view>
						<image class="icon2" src="@/static/img/icon3.png" mode="aspectFit"></image>
					</view>
					<view v-if="userInfo.is_manager == 1" class="left" @tap="show = true">
						<image class="icon1" src="@/static/img/icon2.png" mode="aspectFit"></image>
						<view class="txt">
							{{txt}}
						</view>
						<image class="icon2" src="@/static/img/icon3.png" mode="aspectFit"></image>
					</view>
					<view class="time">
						{{date}}
					</view>
				</view>
			</view>
		</view>
		<view class="list">
			<view class="item" v-for="(item, index) in list" :key="index">
				<view class="top">
					<view class="info">
						<view class="name">工号：{{item.username}}</view>
					</view>
					<view class="post">{{item.name}}</view>
				</view>
				<view class="top">
					<view class="info">
						<view class="name">下单人：{{item.realname}}</view>
					</view>
					<view class="post">运单号：{{item.tool}}</view>
				</view>
				<view class="one">
					<view class="msg">订单编号：{{item.tag}}</view>
					<view class="tag">
						<span v-if="item.status == 0">待付款</span>
						<span v-if="item.status == 1">已支付</span>
						<span v-if="item.status == 10">已发货</span>
						<span v-if="item.status == 11">在途</span>
						<span v-if="item.status == 12">派件</span>
						<span v-if="item.status == 13">退回</span>
						<span v-if="item.status == 14">退签</span>
						<span v-if="item.status == 15">转投</span>
						<span v-if="item.status == 16">疑难</span>
						<span v-if="item.status == 17">拒签</span>
						<span v-if="item.status == 20">已完成</span>
					</view>
				</view>
				<view class="two">
					<!-- <view class="img">
						<image src="@/static/img/ceshi.jpg" mode=""></image>
					</view> -->
					<view class="info msg">
						<view class="tit">{{item.product_name}}</view>
						<view class="sku">{{item.parameters}}</view>
					</view>
					<view class="info right">
						<view class="price">￥{{item.price}}</view>
						<view class="num">X{{item.num}}</view>
					</view>
				</view>
				<view class="the">
					<view class="time">订单时间：{{item.pay_time_text}}</view>
					<!-- <view class="btn on">查看物流</view> -->
				</view>
			</view>
		</view>
		<u-picker :show="show" :columns="columns" @cancel="show = false" @close="show = false" :closeOnClickOverlay="true" keyName="name" @confirm="confirm"></u-picker>
	</view>
</template>

<script>
	import {
		Productorder,
		innerinfo,
		departments
	} from '@/api/inner.js'
export default {
	data() {
		return {
			show:false,
			type: 1,
			list:[],
			total:0.00,
			date:'',
			userInfo:{},
			data:{
				page_size:15,
				type:this.type,
				department_user_id:'',//员工id
				department_id:'',//部门id
				page:1
			},
			columns:[],
			watermark:'',
			txt:'部门筛选',
			last_page:''
		};
	},
	onLoad(e) {
		this.watermark = uni.getStorageSync('watermark')
		this.getInfo()
		let now = new Date()
		let y = now.getFullYear()
		let m = now.getMonth() + 1
		let d = now.getDate()
		this.date = `${y}/${m}/${d}`
		if (e.type == 1) {
			uni.setNavigationBarTitle({
				title: '今日盈利'
			});
		} else {
			uni.setNavigationBarTitle({
				title: '今日亏损'
			});
		}
		this.type = e.type
		this.data.type = e.type;
		if(e.id){
			this.data.department_user_id = e.id
		}
		this.getList()
		this.getBm()
	},
	onReachBottom() {
		if(this.data.page == this.last_page){
			uni.showToast({
				title:'已经是最后一页了',
				icon:'none'
			})
		}else{
			this.data.page++
			this.getList()
		}
	},
	methods: {
		async getBm(){
			let res = await departments()
			console.log(res)
			this.columns.push(res.data)
		},
		confirm(e){
			this.txt = e.value[0].name
			this.data.department_id = e.value[0].id
			this.getList()
			this.show = false
		},
		async getInfo(){
			let res = await innerinfo()
			this.userInfo = res.data
		},
		async getList(){
			if(this.data.page == 1){
				this.list = []
			}
			let res = await Productorder(this.data)
			res.data.list.data.forEach(item => {
				this.list.push(item)
			})
			this.total = res.data.total
			this.last_page = res.data.list.last_page
		},
		routerTo(url){
			uni.navigateTo({
				url:url
			})
		}
	}
};
</script>

<style lang="scss" scoped>
/deep/.uni-page-head {
	background: linear-gradient(124deg, #0a80f8 0%, #016fdf 100%) !important;
}
.main {
	min-height: calc(100vh - 44px);

	.header {
		height: 200px;
		padding: 90px 32px 0;
		font-size: 12px;
		color: #d4e2ff;
		background-image: url('@/static/img/ykBg.png');
		background-repeat: no-repeat;
		background-position: top -44px;
		background-size: 100% 200px;
		position: relative;
		.num {
			font-size: 30px;
			color: #fff;
			margin-top: 5px;
		}
		.sele{
			position: absolute;
			bottom: 0;
			left: 0;
			width: 100%;
			padding: 0 32px;
			.in{
				padding: 13px 15px;
				background-color: #172032;
				border-radius: 10px 10px 0 0;
				display: flex;
				justify-content: space-between;
				align-items: center;
				.left{
					display: flex;
					align-items: center;
					.txt{
						margin: 0 5px;
						background: linear-gradient(70.34631192820734deg, #FEFCD9 0%, #DFC79F 100%);
						-webkit-background-clip: text; /*将设置的背景颜色限制在文字中*/
						-webkit-text-fill-color: transparent; /*给文字设置成透明*/
					}
					.icon1{
						width: 15px;
						height: 15px;
					}
					.icon2{
						width: 7px;
						height: 11px;
					}
				}
				.time{
					font-size: 14px;
					background: linear-gradient(70.34631192820734deg, #FEFCD9 0%, #DFC79F 100%);
					-webkit-background-clip: text; /*将设置的背景颜色限制在文字中*/
					-webkit-text-fill-color: transparent; /*给文字设置成透明*/
				}
			}
		}
	}
	.list {
		padding: 15px;
		.item {
			background-color: #fff;
			border-radius: 10px;
			padding: 10px 15px;
			border: 1px solid #e2e2e2;
			margin-bottom: 20rpx;
			.top {
				display: flex;
				justify-content: space-between;
				align-items: center;
				padding-bottom: 7px;
				border-bottom: 1px solid #e2e2e2;
				margin-bottom: 7px;
				.info {
					display: flex;
					align-items: center;
					font-size: 14px;
					color: #3d3d3d;
					image {
						width: 28px;
						height: 28px;
						border-radius: 100px;
						margin-right: 10px;
					}
				}
				.post {
					font-size: 12px;
					color: #999999;
				}
			}
			.one {
				display: flex;
				justify-content: space-between;
				align-items: center;
				margin-bottom: 10px;
				.msg {
					font-size: 11px;
					color: #666666;
				}
				.tag {
					font-size: 14px;
					color: #3aa2ff;
				}
			}
			.two {
				display: flex;
				justify-content: space-between;
				align-items: center;
				.img {
					image {
						width: 80px;
						height: 70px;
						border-radius: 5px;
					}
				}
				.msg {
					flex: 1;
					margin: 0 10px 0 5px;
				}
				.right {
					align-items: end;
					font-size: 13px;
					color: #666666;
				}
				.info {
					display: flex;
					flex-direction: column;
					justify-content: space-between;
					height: 70px;
					font-size: 14px;
					.tit {
						color: #232323;
						overflow: hidden;
						text-overflow: ellipsis;
						-webkit-line-clamp: 2;
						display: -webkit-box;
						-webkit-box-orient: vertical;
					}
					.sku {
						color: #666666;
					}
				}
			}
			.the {
				display: flex;
				justify-content: space-between;
				align-items: center;
				margin-top: 10px;
				.time {
					font-size: 12px;
					color: #999999;
				}
				.btn {
					font-size: 14px;
					width: 80px;
					padding: 5px 0;
					text-align: center;
					border-radius: 1000px;
				}
				.on {
					color: #fff;
					background-color: #3aa2ff;
				}
			}
		}
	}
}
</style>